Skip to content

Adds priv_getcode#408

Closed
josh-richardson wants to merge 9 commits into
besu-eth:masterfrom
josh-richardson:priv-getcode-reimpl
Closed

Adds priv_getcode#408
josh-richardson wants to merge 9 commits into
besu-eth:masterfrom
josh-richardson:priv-getcode-reimpl

Conversation

@josh-richardson
Copy link
Copy Markdown
Contributor

priv_getCode was previously implemented on another branch, but that became stale & difficult to rebase, so it was quicker to just branch off master and pull in my relevant commits to this branch by cherry-picking.

Signed-off-by: Joshua Richardson joshua@richardson.tech

PR description

Adds priv_getCode, the implementation of eth_getCode but for private transactions.

Fixed Issue(s)

Signed-off-by: Joshua Richardson <joshua@richardson.tech>
Signed-off-by: Joshua Richardson <joshua@richardson.tech>
Signed-off-by: Joshua Richardson <joshua@richardson.tech>
@lucassaldanha lucassaldanha added the privacy private transactions label Feb 19, 2020

public PrivGetCode(
final BlockchainQueries blockchain,
final PrivacyParameters privacyParameters,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like we are passing down the PrivacyParameter object only to get an instance of the privateStateArchive. I think we should change this to receive the privateStateArchive directly.


@Override
public JsonRpcResponse response(final JsonRpcRequestContext requestContext) {
LOG.trace("Executing {}", RpcMethod.PRIV_GET_CODE.getMethodName());
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already have DEBUG log level for JSON-RPC calls. I don't think we need this one.

import org.apache.tuweni.bytes.Bytes;
import org.apache.tuweni.bytes.Bytes32;

public class PrivGetCode implements JsonRpcMethod {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have an abstraction for methods that have the block paramater to handle named or numbers, etc.
Take a look at PrivCall and how it extends AbstractBlockParameterMethod. I believe we should make PrivGetCode extend AbstractBlockParameterMethod.

public JsonRpcResponse response(final JsonRpcRequestContext requestContext) {
LOG.trace("Executing {}", RpcMethod.PRIV_GET_CODE.getMethodName());

final Address address =
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have standardized that for any priv_ methods that have an equivalent eth_ method, we will make the first parameter (index 0) the privacyGroupId. And all other parameters will be the same.

So, the expected params for priv_getCode are:

params: [
   'privacy_group_id',
   '0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b',
   '0x2'  // 2
]

Take a look at PrivCall implementation

final Hash latestStateRoot =
privateStateRootResolver.resolveLastStateRoot(
privacyGroupId,
blockParameter.isNumeric() && blockParameter.getNumber().isPresent()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I mentioned before, extending AbstractBlockParameterMethod should help you handling the block paramter.

@lucassaldanha
Copy link
Copy Markdown
Contributor

Would you please add an entry on CHANGELOG.md under the 1.4.1 section mentioning that we are adding priv_getCode?

@RunWith(MockitoJUnitRunner.class)
public class PrivGetCodeTest {

@Rule public final TemporaryFolder temp = new TemporaryFolder();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

temp doesn't seem to be used

josh-richardson and others added 2 commits February 21, 2020 11:22
Signed-off-by: Joshua Richardson <joshua@richardson.tech>
@josh-richardson
Copy link
Copy Markdown
Contributor Author

josh-richardson commented Feb 21, 2020

I've now addressed all comments from @lucassaldanha and @pinges, however by changing the parameter order, Web3j has had to undergo a refactor which has not yet been released, and therefore the DeployPrivateSmartContractAcceptanceTest will currently fail due to Web3j dependency sending the params in the incorrect order. I've just kicked off a Web3j release, but it may be that I won't be able to update the dependency until Monday.

Signed-off-by: Joshua Richardson <joshua@richardson.tech>
@josh-richardson
Copy link
Copy Markdown
Contributor Author

Bumped the Web3j version, so this should now be ready to go.

Signed-off-by: Joshua Richardson <joshua@richardson.tech>
new JsonRpcRequest(
"2.0",
"priv_getCode",
new Object[] {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to fix the order of the parameters here.

Signed-off-by: Joshua Richardson <joshua@richardson.tech>
Signed-off-by: Joshua Richardson <joshua@richardson.tech>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

privacy private transactions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants